﻿
@{
    ViewBag.Title = "EditRoom";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form class="layui-form" action="" lay-filter="RoomForm">
    <div class="layui-form-item">
        <label class="layui-form-label">房间号</label>
        <div class="layui-input-block">
            <input type="text" name="Name" lay-verify="title" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">楼层</label>
        <div class="layui-input-block">
            <select name="Floors" lay-filter="aihao">
                <option value="" selected="">请选择楼层</option>
                @for (int i = 1; i <=ViewBag.floor; i++)
                {
                    <option value="@i">@i 楼</option>
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">面积</label>
        <div class="layui-input-block">
            <input type="text" name="Area" lay-verify="title" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">朝向</label>
        <div class="layui-input-block">
            <select name="Direction" lay-verify="required">
                <option value="">请选择朝向</option>
                <option value="南">南</option>
                <option value="北">北</option>
                <option value="东">东</option>
                <option value="西">西</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">套餐</label>
        <div class="layui-input-block">
            <select name="PackageId" lay-filter="aihao">
                <option value="" selected="">请选择套餐</option>
                @foreach (var package in ViewBag.Package)
                {
                    <option value="@package.Id">@package.PackageName</option>
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <input type="hidden" value="@ViewBag.HomeId" id="hfRoomId"/>
</form>
<script>
    var form;
    function initRoom() {
        let RoomId = $("#hfRoomId").val()
        $.post("/Room/GetRoom/" + RoomId, function (resp) {
            console.log(resp.data)
            if (resp.code == 0) {
                form.val('RoomForm', resp.data)  //将各项数据绑定到相应的框中
            }
        })
    }
    layui.use(['form', 'layer'], function () {
        form = layui.form;
        var layer = layui.layer;
        var $ = layui.$;

        initRoom()
        //提交事件
        form.on('submit(demo1)', function (data) {
            data.field.Id = $("#hfRoomId").val()
            $.post("/Room/EditRoom",data.field, function (resp) {
                if (resp.code == 0) {
                    layer.msg('修改成功', { icon: 1 }, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                }
            })
            return false;
        });
    });
</script>

